package com.example.java05redis.config;

import org.redisson.Redisson;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.redisson.config.ClusterServersConfig;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.redisson.config.TransportMode;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RedissonConfig {

    @Bean
    public RBloomFilter<String> bloomFilter() {
        Config config = new Config();
        config.setTransportMode(TransportMode.NIO);
//        ClusterServersConfig clusterServersConfig = config.useClusterServers();
//        clusterServersConfig.addNodeAddress(
//                "redis://192.168.223.166:7001","redis://192.168.223.166:7002","redis://192.168.223.166:7003",
//                "redis://192.168.223.166:7004", "redis://192.168.223.166:7005","redis://192.168.223.166:7006");
        SingleServerConfig singleServerConfig = config.useSingleServer();
        //可以用"rediss://"来启用SSL连接
        singleServerConfig.setAddress("redis://127.0.0.1:6379");
        //singleServerConfig.setPassword("123456");
        RedissonClient redisson = Redisson.create(config);
        //创建布隆过滤器
        RBloomFilter<String> bloomFilter = redisson.getBloomFilter("person-filter");
        //初始化
        bloomFilter.tryInit(10000000L, 0.03);
        return bloomFilter;
    }

    @Bean
    public RedissonClient redissonClient(){
        Config config = new Config();
        config.setTransportMode(TransportMode.NIO);
//        ClusterServersConfig clusterServersConfig = config.useClusterServers();
//        clusterServersConfig.addNodeAddress(
//                "redis://192.168.223.166:7001","redis://192.168.223.166:7002","redis://192.168.223.166:7003",
//                "redis://192.168.223.166:7004", "redis://192.168.223.166:7005","redis://192.168.223.166:7006");
        SingleServerConfig singleServerConfig = config.useSingleServer();
        //可以用"rediss://"来启用SSL连接
        singleServerConfig.setAddress("redis://127.0.0.1:6379");
        //singleServerConfig.setPassword("123456");
        RedissonClient redisson = Redisson.create(config);
        return redisson;
    }
}
